<template>
  <div class="portlet">
    <a-spin :spinning="spinning">
      <pre-textarea
        :title="$t('pro.public.header.Billing')"
        :html-for-editor="htmlForEditor"
        @click="handleOKClick"
      ></pre-textarea>
    </a-spin>
  </div>
</template>

<script>
import { getBilling, changeBilling } from "../../../api/user";

import preTextarea from "../../../components/common/custom/PreTextarea";
export default {
  name: "EditBilling",
  components: { preTextarea },
  data() {
    return {
      htmlForEditor: "",
      spinning: false
    };
  },
  methods: {
    handleOKClick(htmlForEditor) {
      if (!!htmlForEditor) {
        this.spinning = true;
        setTimeout(() => {
          changeBilling(htmlForEditor)
            .then(res => {
              let { code } = res.data;
              if (code == 200) {
                this.$message.success(this.$t("pro.public.buttonSaveEd"));
                this.initData();
              }
            })
            .finally(() => {
              this.spinning = false;
            });
        }, 1000);
      }
    },
    initData() {
      this.spinning = true;
      setTimeout(() => {
        getBilling()
          .then(res => {
            let { code, data } = res.data;
            if (code == 200) {
              this.htmlForEditor = data;
            }
          })
          .finally(() => {
            this.spinning = false;
          });
      }, 1000);
    }
  },
  created() {
    this.initData();
  }
};
</script>
